package com.dyl.system.service.impl;


import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.dyl.common.core.utils.LayerData;
import com.dyl.common.core.web.domain.SysLuckySheet;
import com.dyl.system.dao.LuckySheetDao;

import com.dyl.system.service.LuckySheetService;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;


@Service
@Transactional(readOnly = true,rollbackFor = Exception.class)
public class LuckySheetServiceImpl extends ServiceImpl<LuckySheetDao, SysLuckySheet> implements LuckySheetService {
    @Override
    public LayerData<SysLuckySheet> list(Integer page, Integer limit, String name) {
        LayerData<SysLuckySheet> layerData = new LayerData<>();
        EntityWrapper<SysLuckySheet> wrapper = new EntityWrapper();
        wrapper.where("name IS NOT NULL").like("name", name);
        List<SysLuckySheet> sysLuckySheets1 = baseMapper.selectPage(new Page<>(page, limit), wrapper);
        layerData.setCount(sysLuckySheets1.size());
        layerData.setData(sysLuckySheets1);
        return layerData;
    }

    @Transactional(readOnly = false,rollbackFor = Exception.class)
    @Override
    public Boolean saveSysLuckySheet(SysLuckySheet sysLuckySheet) {
        return insertOrUpdate(sysLuckySheet);
    }

    @Transactional(readOnly = false,rollbackFor = Exception.class)
    @Override
    public boolean updateSysLuckySheet(SysLuckySheet sysLuckySheet) {
            return insertOrUpdate(sysLuckySheet);
    }

    @Override
    public SysLuckySheet getByID(Long id) {
        return selectById(id);
    }

}
